package com.gw.detail.controllor.detail;

import com.gw.detail.domain.Lkwb;
import com.gw.detail.service.ILkwbService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 货客车外部损坏Controller
 *
 * @author WangBin
 * @date 2021-04-30
 */
@RestController
@RequestMapping("/detail/lkwb")
public class LkwbController extends BaseController {
    @Autowired
    private ILkwbService lkwbService;

    /**
     * 查询货客车外部损坏列表
     */
    @PreAuthorize("@ss.hasPermi('detail:lkwb:list')")
    @GetMapping("/list")
    public TableDataInfo list(Lkwb lkwb) {
        startPage();
        List<Lkwb> list = lkwbService.selectLkwbList(lkwb);
        return getDataTable(list);
    }

    /**
     * 导出货客车外部损坏列表
     */
    @PreAuthorize("@ss.hasPermi('detail:lkwb:export')")
    @Log(title = "货客车外部损坏", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(Lkwb lkwb) {
        List<Lkwb> list = lkwbService.selectLkwbList(lkwb);
        ExcelUtil<Lkwb> util = new ExcelUtil<Lkwb>(Lkwb.class);
        return util.exportExcel(list, "货客车外部损坏数据");
    }

    /**
     * 获取货客车外部损坏详细信息
     */
    @PreAuthorize("@ss.hasPermi('detail:lkwb:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(lkwbService.selectLkwbById(id));
    }

    /**
     * 新增货客车外部损坏
     */
    @PreAuthorize("@ss.hasPermi('detail:lkwb:add')")
    @Log(title = "货客车外部损坏", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Lkwb lkwb) {
        return toAjax(lkwbService.insertLkwb(lkwb));
    }

    /**
     * 修改货客车外部损坏
     */
    @PreAuthorize("@ss.hasPermi('detail:lkwb:edit')")
    @Log(title = "货客车外部损坏", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Lkwb lkwb) {
        return toAjax(lkwbService.updateLkwb(lkwb));
    }

    /**
     * 删除货客车外部损坏
     */
    @PreAuthorize("@ss.hasPermi('detail:lkwb:remove')")
    @Log(title = "货客车外部损坏", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(lkwbService.deleteLkwbByIds(ids));
    }
}
